import time
import pygame as pg

score = 0
flag1 = False  # if the game is over

isBall2 = False
isBall3 = False


class Ball:

    ball = [0, 0]
    speed = [0, 0]
    radius = 0
    screen = None

    def __init__(self, ball, speed, radius, screen):
        self.radius = radius
        self.ball = ball
        self.speed = speed
        self.screen = screen

    def draw(self, color):
        pg.draw.circle(self.screen, color, self.ball, self.radius)

    def move_ball(self, paddle):
        global score
        global flag1
        time.sleep(0.001)
        self.ball[0] += self.speed[0]
        self.ball[1] += self.speed[1]

        # at the edge
        if self.ball[1] - self.radius == 0:
            self.speed[1] *= -1
        if self.ball[0] + self.radius == 640 or self.ball[0] - self.radius == 0:
            self.speed[0] *= -1

        # on the paddle
        if self.ball[1] + self.radius == paddle.top and paddle.left < self.ball[0] + self.radius < paddle.right:
            self.speed[1] *= -1
            score += 10

        # game over
        if self.ball[1] + self.radius == 480:
            score = 0
            self.ball[0] = 100
            self.ball[1] = 100
            flag1 = True
